unit Multiplicacao;

interface

uses
  MVCInterfaces;

type
  TModeloMultiplicacao = class(TInterfacedObject, IModelo)
    private
      FValor1: Double;
      FValor2: Double;

      FOnModelChanged: TModelChangedEvent;
      FSolucao: Double;

      procedure SetValor1(const Valor: Double);
      procedure SetValor2(const Valor: Double);

      function GetOnModelChanged: TModelChangedEvent;

      procedure SetOnModelChanged(Valor: TModelChangedEvent);

      procedure Initialize;
      procedure SetSolucao(const Valor: Double);

    public
      constructor Create; reintroduce;

      function Multiplicacao: Double;

      property Valor1: Double read FValor1 write SetValor1;
      property Valor2: Double read FValor2 write SetValor2;
      property Solucao: Double read FSolucao write SetSolucao;
      property OnModelChanged: TModelChangedEvent read GetOnModelChanged write SetOnModelChanged;
  end;
implementation

{ TModeloMultiplicacao }

constructor TModeloMultiplicacao.Create;
begin
  Initialize;
end;

function TModeloMultiplicacao.GetOnModelChanged: TModelChangedEvent;
begin
  Result := FOnModelChanged;
end;

procedure TModeloMultiplicacao.Initialize;
begin
  Valor1 := 0;
  Valor2 := 0;
  Solucao := 0;
end;

function TModeloMultiplicacao.Multiplicacao: Double;
begin
  Result := Valor1 * Valor2;
  Solucao := Result; // nunca vi isso mas tudo bem

  if(Assigned(OnModelChanged))then
  begin
    OnModelChanged;
  end;
end;

procedure TModeloMultiplicacao.SetOnModelChanged(Valor: TModelChangedEvent);
begin
  FOnModelChanged := Valor;
end;

procedure TModeloMultiplicacao.SetSolucao(const Valor: Double);
begin
  FSolucao := Valor;
end;

procedure TModeloMultiplicacao.SetValor1(const Valor: Double);
begin
  FValor1 := Valor;
end;

procedure TModeloMultiplicacao.SetValor2(const Valor: Double);
begin
  FValor2 := Valor;
end;

end.
 